package com.sright.bcard.cms.controller;

import com.sright.bcard.common.service.share.mvcresolver.BodyFiled;
import com.sright.bcard.common.service.share.mvcresolver.EnableLoginAuth;
import com.sright.bcard.common.share.service.WxappService;
import com.sright.bcard.common.service.share.dto.content.UserDTO;
import com.sright.bcard.content.dal.entity.CardUserInfoDO;
import com.sright.bcard.content.share.service.UserService;
import com.sright.bcard.enterprise.share.service.MaterialService;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author: lumf
 * Date: 2020/8/13 5:23 PM
 */
@RestController
@Slf4j
public class CardManageController {
    @Autowired
    MaterialService materialService;

    @Autowired
    UserService userService;

    @Autowired
    WxappService wxappService;

    @GetMapping("/person/list")
    @EnableLoginAuth
    public SrightResponse getCardList(String keyword,
                                              @RequestParam(value = "status") Integer  enableStatus,
                                              @RequestParam(value = "begin_time") Long beginTime,
                                              @RequestParam(value = "end_time") Long endTime,
                                              @RequestParam(value = "page") Integer pageIndex,
                                              Integer pageSize)  {
//        Pager<?> pager =

        return SrightResponse.defaultSuccess();
    }

    @GetMapping("/person/qrcode")
    @EnableLoginAuth
    public SrightResponse getPersonalCardQrcode(Long cardId, Long userId) throws Exception {
        String path = String.format("pages/card/main?t=3&cardId=%d&userId=%d&lang=zh&u=%d", cardId, userId, 1);
        return wxappService.createQrCode(path);
    }


    @GetMapping("/enterprise/account/card/list")
    @EnableLoginAuth
    public SrightResponse getCardListOfEnterprise(@RequestParam(value = "enterprise_id")  Long enterpriseId,
                                                  String keyword,
                                                  @RequestParam(value = "status") String  enableStatus,
                                                  @RequestParam(value = "begin_time") Long beginTime,
                                                  @RequestParam(value = "end_time") Long endTime,
                                                  @RequestParam(value = "page") Integer pageIndex,
                                                  Integer pageSize)  {
        return null;
    }

    @GetMapping("/enterprise/account/qrcode/get")
    @EnableLoginAuth
    public SrightResponse getEnterpriseCardQrcode(Long cardId, Long userId) throws Exception {
        String path = String.format("pages/card/main?t=3&cardId=%d&userId=%d&lang=zh&u=%d", cardId, userId, 2);
        return wxappService.createQrCode(path);
    }

    @PostMapping("/content/check_status/edit")
    @EnableLoginAuth
    public SrightResponse updateCheckStatusOfCardUserInfo(@BodyFiled("id") Long cardUserId, @BodyFiled("status") Integer checkStatus) {
        userService.updateCheckStatus(cardUserId,checkStatus);
        return SrightResponse.defaultSuccess();
    }
}
